import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import type { UserInfo } from '@/type/user'

export const useUserStore = defineStore('user', () => {
  const token = ref('')
  const userData = ref({} as UserInfo)
  const isLoggedIn = computed(() => !!userData.value && !!token.value)
  const setUserInfo = (data: UserInfo) => {
    token.value = data.access_token
    userData.value = data
  }
  const reset=()=>{
    token.value=''
    userData.value={} as UserInfo
  }
  return { token, userData, setUserInfo,reset,isLoggedIn }
},
  {
    // @ts-ignore
    unistorage: true, // 开启后对 state 的数据读写都将持久化
  },)
